 <template>
    <div class="search-box">
          <!-- 位置信息 -->
      <div class="location bottom-gray-line ">
        <div class="city" @click="cityClick">{{ currentCity.cityName }}</div>
        <div class="position" @click="positionClick">
          <span class="text">我的位置</span>
          <img src="@/assets/img/home/icon_location.png" alt="">
        </div>
      </div>
          <!-- 日期范围 -->
      <div class="section date-range bottom-gray-line " @click="showCalendar = true">
        <div class="start">
          <div class="date">
            <span class="tip">入住</span>
            <span class="time" @click="isShowTime('start')">{{ startDateStr }}</span>
          </div>
          <div class="stay">共{{ stayCount }}晚</div>
        </div>
        <div class="end">
          <div class="date">
            <span class="tip">离店</span>
            <span class="time" @click="isShowTime('end')">{{ endDateStr }}</span>
          </div>
        </div>
        <van-calendar v-model:show="show" @confirm="onConfirm" />
      </div>
        <!-- 价格/人数选择 -->
    <div class="section price-counter bottom-gray-line">
      <div class="start">价格不限</div>
      <div class="end">人数不限</div>
    </div>
    <!-- 关键字 -->
    <div class="section keyword bottom-gray-line">关键字/位置/民宿名</div>

     <!-- 热门建议 -->
     <div class="section hot-suggests">

     </div>

    </div>
 </template>
 <script setup>
  import {useRouter } from 'vue-router'
  import {ref , reactive, computed} from 'vue'
  import useCityStore from '@/stores/modules/city'
  import { formatMonthDay ,getDiffDays} from '@/utils/format_date'
import { storeToRefs } from 'pinia'

  const cityStore = useCityStore()
  const { currentCity } = storeToRefs(cityStore)
  const router = useRouter()
  // const currentCity = reactive({
  //   cityName:'上海',
  //   age:18
  // })
  const cityClick = ()=>{
    router.push('/city')
  }
  const positionClick = () => {
      navigator.geolocation.getCurrentPosition(res => {
        console.log("获取位置成功:", res)
      }, err => {
        console.log("获取位置失败:", err)
      }, {
        enableHighAccuracy: true,
        timeout: 5000,
        maximumAge: 0
      })
}
// 日期控件
const showCalendar = ref()
const timeValue = ref('')
const startDateStr = ref(formatMonthDay(new Date().getTime()))
const endDateStr = ref(formatMonthDay((new Date().getTime())+24*60*60*1000))
const stayCount = ref(1)


const date = ref('');
const show = ref(false);

const formatDate = (date) => `${date.getMonth() + 1}/${date.getDate()}`;
const onConfirm = (value) => {
      show.value = false;
      date.value = formatDate(value);
      if(timeValue.value === 'start'){
        startDateStr.value =formatMonthDay(date.value) 
      }else{
        endDateStr.value = formatMonthDay(date.value)
      }
    };
const isShowTime = (parme)=>{
  console.log("parme",parme);
  timeValue.value = parme
  show.value=true
}
 </script>
 <style lang="less" scoped>
    // :deep(.van-popup--bottom){
    //   top:25%
    //  }
//  .search-box {
//   --van-calendar-popup-height: 75%;
// }

.location {
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 20px;

  .city {
    flex: 1;
    color: #333;
    font-size: 15px;
  }

  .position {
    width: 74px;
    display: flex;
    align-items: center;

    .text {
      position: relative;
      top: 2px;
      color: #666;
      font-size: 12px;
    }

    img {
      margin-left: 5px;
      width: 18px;
      height: 18px;
    }
  }
}

.section {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 0 20px;
  color: #999;
  height: 44px;

  .start {
    flex: 1;
    display: flex;
    height: 44px;
    align-items: center;
  }

  .end {
    min-width: 30%;
    padding-left: 20px;
  }

  .date {
    display: flex;
    flex-direction: column;

    .tip {
      font-size: 12px;
      color: #999;
    }

    .time {
      margin-top: 3px;
      color: #333;
      font-size: 15px;
      font-weight: 500;
    }
  }
}

.date-range {
  height: 44px;
  .stay {
    flex: 1;
    text-align: center;
    font-size: 12px;
    color: #666;
  }
}

.price-counter {
  .start {
    border-right: 1px solid  var(--line-color);
  }
}

.hot-suggests {
  margin: 10px 0;
  height: auto;

  .item {
    padding: 4px 8px;
    margin: 4px;
    border-radius: 14px;
    font-size: 12px;
    line-height: 1;
  }
}

.search-btn {
  .btn {
    width: 342px;
    height: 38px;
    max-height: 50px;
    font-weight: 500;
    font-size: 18px;
    line-height: 38px;
    text-align: center;
    border-radius: 20px;
    color: #fff;
    background-image: var(--theme-linear-gradient);
  }
}

 </style>